function getOldAscent(node) {
	var index;
	var parent;
	
	parent=node.parent;
	
	i=parent.children.indexOf(node);
	
	if(i==0) {
		return 0;
	}
	
	return {
		ascent:parent.children[i-1].ascent,
		descent:parent.children[i-1].descent,
	}
	
}


function offSetForConglam(node) {
	var operatorNode;
	var ascent=0;
	var descent=0;
	var oldMetric;

	var ascentTop=0;
	var descentTop=0;
	var ascentBottom=0;
	var descentBottom=0;
	
	var heightTop=0;
	var heightBottom=0;
	
	var length;
	
	node.ascent=0;
	node.descent=0;
	
	operatorNode=node.children;
	
	oldMetric=getOldAscent(node);
	
	selfAscent=oldMetric.ascent;
	selfDescent=oldMetric.descent;
	
	length=operatorNode.length;
	
	if(length<=0) 
	{
		return 0;
	}
	
	else {
		for(var i=0;i<length;i++){
			element=operatorNode[i];
			if(element.operator=="up")
			{
//				heightTop=element.height;
				
				ascentTop=ascentChildren(element);
				descentTop=descentChildren(element);

				element.node.css('bottom',selfAscent*(1/2)+descentTop);
				node.ascent=ascentTop+descentTop+selfAscent/2;

			}
			else if(element.operator=="down")
			{
//				heightBottom=element.height;

				ascentBottom=ascentChildren(element);
				descentBottom=descentChildren(element);
				
				element.node.css('bottom',selfAscent/2-ascentBottom);
				node.descent=ascentBottom+descentBottom-selfAscent/2;
			}	
		}
	}
	node.width=maxWidthChildren(node);
	
}

function conglommeration(keyCode) {
	var level;
	var parent=null; // locate parent. here parent means previous sibling

	
	level=caret.level; 
	
	if(keyCode==94||keyCode==95) { //	Taking care of ^ and _ conglammerations.

		if(caret.operator=="conglam") { // if conglammeration already exists, inserting after existing one
		
			if((temp=caret.childrenWithOperator(operatorType(keyCode)))!=null) // if this type node already exists
			{ 	
				caret=temp.children[temp.children.length-1]; // go to the last.
				return; //insert after existing ones
			}
			else 
			{ // if not, then creating it
				parent=caret.previous();
			}
		}
		else if(caret.next()!=null&&caret.next().operator=="conglam") { // if conglammeration already exists, inserting before existing one
			if((temp=caret.next().childrenWithOperator(operatorType(keyCode)))!=null) // if this type node already exists
			{
				caret=temp.children[temp.children.length-1];
				return; //insert after existing ones
			}
			else { // if not, then creating it
				parent=caret;
				caret=caret.next();
			}
		}
		else { // conglammeration doesn't exist.
			
			caret=superOperatorInsert(caret,"conglam")
	
		}
		// Adjusting Conglameration Node
			
		// Add Operator Node, Operator only changes bottom position
		
		caret=subOperatorAppend(caret,operatorType(keyCode));
		
		// Add Content Node
		
		caret=contentNodeAppend(caret,0);
					
	}

}

function superscript(node) {
	conglommeration(94);
}

function subscript(node) {
	conglommeration(95);
}